package woa.sort.test20230210;

import java.util.Arrays;

/**
 * @author wangpeng
 * @date 2023/2/10 11:05
 */
public class BubbleSort1 {

    public static void sort(int[] arr) {
        if (arr == null || arr.length == 0) {
            return;
        }

        for (int i = 0; i < arr.length; i++) {
            boolean isFinish = true;
            for (int j = 0; j < arr.length - i - 1; j++) {
                if (arr[j] > arr[j + 1]) {
                    int temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                    isFinish = false;
                }
            }
            if (isFinish) {
                return;
            }
        }
    }

    public static void main(String[] args) {
        int[] arr = {3,4,1,3,5,6,78,1,3,3,3,2};
        sort(arr);
        System.out.println(Arrays.toString(arr));
    }
}
